<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib prefix="sb" uri="/struts-bootstrap-tags"%>
<%@ include file="/page/company/comHeader.jsp" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>订单管理列表</title>
<script type="text/javascript" src="<%=basePath%>js/tablecreate/jlinq.js"></script>
<script type="text/javascript" src="<%=basePath%>js/tablecreate/jquery-dynamicTable.js"></script>
<script type="text/javascript" src="<%=basePath%>js/tablecreate/pager.js"></script> 
<script type="text/javascript" src="<%=basePath%>js/tablecreate/modal.js"></script>

<style type="text/css">
a:LINK{text-decoration: none;color:black;}
a:visited {text-decoration:none ; color:black;}
a:hover {text-decoration:underline ; color:black;}
a:active {text-decoration:none ; color:black;} 
</style>
<sb:head/>
</head>
<body  onload="comOrderList()">

<h3>订单列表</h3>
<div style="background-color:#dcdcdc;width: 100%;height:36px;">
<div style="background-color:#dcdcdc;width: 500px;height:36px;float:left;">
<!-- <input class="btn btn-info" onclick="add('menu_editMenu')" type="button" value="上传菜单" />  -->
<s:hidden value="%{#session.company.comId}" id="comId"></s:hidden>
<%-- <s:hidden value="%{comId}" id="comId"></s:hidden> --%>
<input id="userName" class="input-medium search-query" name="userName" value=""/>
<select id="type" style="width:100px;">
<option value="">支付方式</option>
<option value=0>网上支付</option>
<option value=1>餐到付款</option>
</select>
<select id="status" style="width:100px;">
<option value="">支付状态</option>
<option value=0>未支付</option>
<option value=1>已支付</option>
</select>
<input type="button" class="btn btn-success" id="" onclick="searchList()" value="查询"/>
</div>
<div style="background-color:#dcdcdc;width: 360px;height:36px;float:right;">
<select id="selDate" onchange="searchListByselDate()" style="width: 80px;height: 80%" >
<option value="">时间</option>
<option value='<s:property value="dateMap.currDate"/>-<s:property value="dateMap.currDate"/>'>今天</option>
<option value='<s:property value="dateMap.yesterday"/>-<s:property value="dateMap.currDate"/>'>昨天</option>
<option value='<s:property value="dateMap.day7"/>-<s:property value="dateMap.currDate"/>'>最近7天</option>
<option value="<s:property value="dateMap.day15"/>-<s:property value="dateMap.currDate"/>">最近15天</option>
<option value="<s:property value="dateMap.currMonth"/>-<s:property value="dateMap.currDate"/>">本月</option>
<option value="<s:property value="dateMap.upstartmonth"/>-<s:property value="dateMap.upendmonth"/>">上月</option>
</select>
<input placeholder="起始时间" id="sDate" type="text" style="width: 120px;height: 80%" onClick="WdatePicker()"/><input placeholder="结束时间" onchange="searchListByDate()" id="eDate" style="width: 120px;height: 80%" type="text" onClick="WdatePicker()"/>
<img style="margin-top: -10px;" width="30px;" height="35px;" alt="" src="<%=basePath%>js/datepicker/skin/datePicker.gif">
</div>
</div>
<div id="lists" style="width: 100%;height: 400px;">
<div id="list" ></div>
<div id="page"></div>
</div>
<script type="text/javascript">
var comId=$("#comId").val();
var url=[{loadUrl:"order_getOrders?comId="+comId,editUrl:"<%=basePath%>com/order_editOrder?orderId=",delUrl:"order_delOrder"}];//请求地址
var postData={userName:$("#userName").val(),payType:$("#type").val(),payStatus:$("#status").val()};
var pageId="page";
var objClassName="list_light";
var objColumn = [
					{ ColumnName: "订单编号", DataId: "orderId", Width: 200, DataAlign: "left", Format: null, OnClick: null },
					{ ColumnName: "用户", DataId: "userName", Width: 100, DataAlign: "left", Format: null, OnClick: null },
					{ ColumnName: "联系电话", DataId: "userPhone", Width: 100, DataAlign: "left", Format: null, OnClick: null },
					{ ColumnName: "地址", DataId: "userAddress", Width: 100, DataAlign: "left", Format: null, OnClick: null },
					{ ColumnName: "备注", DataId: "userRemark", Width:200, DataAlign: "left", Format: null, OnClick: null },
					{ ColumnName: "下单时间", DataId: "orderStartdate", Width:200, DataAlign: "left", Format: null, OnClick: null },
					{ ColumnName: "完成时间", DataId: "orderEnddate", Width:200, DataAlign: "left", Format: null, OnClick: null },
					{ ColumnName: "支付方式", DataId: "payType", Width:200, DataAlign: "left", Format: null, OnClick: null },
					{ ColumnName: "支付状态", DataId: "payStatus", Width:200, DataAlign: "left", Format: null, OnClick: null },
					{ ColumnName: "订单状态", DataId: "orderFlage", Width:200, DataAlign: "left", Format: null, OnClick: null },
					{ ColumnName: "配送人", DataId: "attName", Width:200, DataAlign: "left", Format: null, OnClick: null },
					{ ColumnName: "操作", DataId: "Operation", Width: 200, DataAlign: "left", Format: null, OnClick: null },
                 ];
function comOrderList(){
	   $.ajax({
			type: "post",
	        url: url[0].loadUrl,
	        data: postData,
	        dataType: "json",
	        success: function(data){
          var objData = new Array(data.list.length);
          for(var i=0;i<data.list.length;i++){
              var orderFlage="";
              var op="";
              if(data.list[i].orderFlage==0){
            	  orderFlage="未发货";
            	  op+="<a class='edit'onclick=\"edit('"+url[0].editUrl+""+data.list[i].orderId+"')\" title=\"编辑\" href=\"javascript:void(0)\" id='"+data.list[i].orderId+"'>编辑</a>&nbsp;&nbsp;";
                  if(data.list[i].payType=="网上支付"&&data.list[i].payStatus=="已支付"){
                	  op+="<a class='edit'onclick=\"edit('order_editAtten?comId="+comId+"&street="+data.list[i].userAddress+"&orderId="+data.list[i].orderId+"')\" title=\"配送\" href=\"javascript:void(0)\" '>配送</a>&nbsp;&nbsp;";
                      }
                  if(data.list[i].payType=="餐到付款"){
                	  op+="<a class='edit'onclick=\"edit('order_editAtten?comId="+comId+"&street="+data.list[i].userAddress+"&orderId="+data.list[i].orderId+"')\" title=\"配送\" href=\"javascript:void(0)\" '>配送</a>&nbsp;&nbsp;";
                      }
                  }else if (data.list[i].orderFlage==1) {
                	  orderFlage="已发货";
                	  op+="<a href='order_updateFlage?orderId="+data.list[i].orderId+"&orderFlage=1'>完成</a>&nbsp;&nbsp;";
				}else{
					orderFlage="完成";
					}
               op+="<a href='javascript:void(0);' onclick='delInfo(\"order_delOrder?orderId="+data.list[i].orderId+"\")' title='删除'>删除</a>&nbsp;&nbsp; ";
               op+="<a href='orderitem_orderItemList?orderId="+data.list[i].orderId+"' target='_bank' title='订单详情' >订单详情</a>";
           	  objData[i]={orderId:data.list[i].orderId,userName:data.list[i].userName,userPhone:data.list[i].userPhone,
       			     userAddress:data.list[i].userAddress,userRemark:data.list[i].userRemark,
       			  orderStartdate:data.list[i].orderStartdate,orderEnddate:data.list[i].orderEnddate,
       			payType:data.list[i].payType,payStatus:data.list[i].payStatus,orderFlage:orderFlage,attName:data.list[i].attName,Operation:op}; 
              }
               $("#list").MakeTable(objColumn, objData, objClassName);
        	  $("#page").MakePage(data.page[0]);
		        }
			});
	   }
function searchList(){
	var page=$("#selPage").val();
	var pageRow=$("#selRow").val();
	postData={userName:$("#userName").val(),payType:$("#type").val(),payStatus:$("#status").val(),initPage:page,pageRow:pageRow};
	comOrderList();
}
var j=0;
function OrderSort(order){
	var order=order;
	j++;
	if(j%2==0){
          var sort="desc";
		}else if (j%3==0) {
			var sort="asc";
		}else{
      order="created";
      var sort="desc";
			}
	var page=$("#selPage").val();
	var pageRow=$("#selRow").val();
	postData={userName:$("#userName").val(),payType:$("#type").val(),payStatus:$("#status").val(),order:order,sort:sort,initPage:page,pageRow:pageRow};
	comOrderList();
}
function goPage(){
	var page=$("#selPage").val();
	var pageRow=$("#selRow").val();
	postData={userName:$("#userName").val(),payType:$("#type").val(),payStatus:$("#status").val(),initPage:page,pageRow:pageRow};
	comOrderList();
}
function changePage(page){
	var pageRow=$("#selRow").val();
	postData={userName:$("#userName").val(),payType:$("#type").val(),payStatus:$("#status").val(),initPage:page,pageRow:pageRow};
	comOrderList();
}
function goRow(){
	var pageRow=$("#selRow").val();
	var page=$("#selPage").val();
	comOrderList();
}
function searchListByselDate(){
    var date=$("#selDate").val();
  //  alert(date);
    var sDate=date.substring(0,(date.length-1)/2);
    var eDate=date.substring((date.length+1)/2,date.length);
    ///alert(sDate);alert(eDate);
    var page=$("#selPage").val();
	var pageRow=$("#selRow").val();
	postData={userName:$("#userName").val(),s_date:sDate,e_date:eDate,initPage:page,pageRow:pageRow};
	comOrderList();
}
function searchListByDate(){
	var sDate=$("#sDate").val();
	var eDate=$("#eDate").val();
	//alert(sDate);alert(eDate);
	var page=$("#selPage").val();
	var pageRow=$("#selRow").val();
	postData={userName:$("#userName").val(),s_date:sDate,e_date:eDate,initPage:page,pageRow:pageRow};
	comOrderList();
}
</script>
<%@ include file="/page/common/modal.jsp"%>
<jsp:include page="/page/company/comFooter.jsp"></jsp:include>
</body>
</html>